package com.wxy.demo.controller;

import com.wxy.demo.dao.DataSourceInfoDao;
import com.wxy.demo.dao.InterfaceInfoDao;
import com.wxy.demo.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *
 * </p>
 *
 * @author e-Xiaoyuan.Wang
 * @since 2022/4/12 13:32
 */
@Transactional
@RestController
@RequestMapping("/report")
public class ReportController {

    @Autowired
    private DataSourceInfoDao dataSourceInfoDao;

    @Autowired
    private InterfaceInfoDao interfaceInfoDao;

    @Autowired
    private UserDao userDao;

    @GetMapping("/info")
    private Object report() {
        Map<String, Object> map = new HashMap<>();
        map.put("datasourceCount", dataSourceInfoDao.count());
        map.put("interfaceCount", interfaceInfoDao.count());
        map.put("userCount", userDao.count());
        map.put("requestCount", interfaceInfoDao.sumRequestCount());
        map.put("openApiCount", interfaceInfoDao.countOpenApi());
        return map;
    }
}
